<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

$workspaces = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}admin_users_to_workspaces WHERE user_id = '{$USER->userid}'");
foreach($workspaces as $k=>$v){
    $workspaces[$k] = array_merge($v, $DB->fetchRow("SELECT * FROM {$CONFIG->dbprefix}workspaces WHERE id = '{$v['workspace_id']}'"));
    $workspaces[$k]['title'] = $CORE->getContentLang('workspace_title', $v['workspace_id']);
}
$langs = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}languages WHERE is_active = 1 ORDER BY keyname ASC");
foreach($langs as $k=>$v){
    $code = explode('_', $v['keyname']);
    $langs[$k]['code'] = strtolower($code[1]);
}
$SMARTY->assign('langs', $langs);
$SMARTY->assign('workspaces', $workspaces);

$SMARTY->assign('_CHANGE_WORKSPACE_OPTIONS', $SMARTY->fetch('admin/change-workspace.tpl'));
$SMARTY->assign('_CHANGE_LANGUAGE_OPTIONS', $SMARTY->fetch('admin/change-language.tpl'));





















if(get('JFXGetAjaxContent')!='1') return;

$resultObj = new stdClass();

$js = $params['_JS'];
$css = $params['_CSS'];

$cssContent = '';
$jsContent = '';

if(!class_exists('phpQuery', false)) include($CONFIG->classesDir.'/PHPQuery/phpQuery.php');

$dom = phpQuery::newDocument($js);
$jss = pq('script');
foreach($jss as $k=>$jsBlock){
    $jsContent .= $jsBlock->nodeValue;
}

$dom = phpQuery::newDocument($css);
$csss = pq('style');
foreach($csss as $k=>$cssBlock){
    $cssContent .= $cssBlock->nodeValue;
}

$main = //$params['_BREADCRUMBS'].//'<pre>'.htmlentities($jsContent).'</pre>'.
    $params['_ERROR'].$params['_SUCCESS'].''.
    $params['_CONTENT'].$params['_MAIN'].'<div class="clear"></div>';

$params['_JS'] = $jsContent;
$params['_CSS'] = $cssContent;

$resultObj->_JS = $params['_JS'];
$resultObj->_JSLINKS = $params['_JSLINKS_ARRAY'];
$resultObj->_CSS = $params['_CSS'];
$resultObj->_CSSLINKS = $params['_CSSLINKS_ARRAY'];
$resultObj->_BREADCRUMBS = $params['_BREADCRUMBS'];
$resultObj->_HEAD = $params['_HEAD'];
$resultObj->_MAIN = $main;

/*while(ob_get_level()>0) ob_end_clean();
var_dump($resultObj->_JSLINKS);
exit;*/

$SMARTY->assign('_JFX_JSON_RES', json_encode($resultObj));

/*
$fh = fopen($this->dirname.'/_JFX_JSON_RES.txt', 'w');
fwrite($fh, json_encode($resultObj));
fclose($fh);

$fh = fopen($this->dirname.'/_JFX_JS_RES.js', 'w');
fwrite($fh, $resultObj->_JS);
fclose($fh);
*/




